package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliyunUploadImgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云 OSS云服务配置
 */
@Slf4j
@Configuration
public class AliyunOSSConfig {


    /**
     * 注入图片上传  OSS云服务bean
     */
    @Bean
    @ConditionalOnMissingBean
    public AliyunUploadImgUtil aliyunUploadImgUtil(AliOssProperties aliOssProperties) {
        log.info("开始创建-阿里云OSS云服务bean: {}", aliOssProperties);
        return new AliyunUploadImgUtil(
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName(),
                aliOssProperties.getProjectName());
    }

}
